import { queryRoleList } from '@/service/user';
import type { ProColumns } from '@ant-design/pro-components';

export const getRoleList = async () => {
  const list = await queryRoleList()

  return list.map(role => ({
    ...role,
    key: role.id,
    value: role.id,
    label: role.name,
  }))
}

export const defaultColumns: ProColumns<API.RuleListItem>[] = [
  {
    title: '账号ID',
    dataIndex: 'id',
    key: 'id',
    width: 70,
  },
  {
    title: '账号',
    dataIndex: 'account',
    width: 170,
  },
  {
    title: '用户名',
    dataIndex: 'username',
    width: 120,
  },
  {
    title: '权限',
    dataIndex: 'roleId',
    width: 110,
    valueType: 'select',
    request: async () => await getRoleList(),
    render: (text, item) => item?.roleName,
  },
  {
    title: '创建人',
    dataIndex: 'createdByAccount',
    search: false,
    width: 150,
  },
  {
    title: '创建时间',
    dataIndex: 'createdTime',
    search: false,
    width: 160,
  },
  {
    title: '更新人',
    dataIndex: 'updatedByAccount',
    search: false,
    width: 150,
  },
  {
    title: '更新时间',
    dataIndex: 'updatedTime',
    search: false,
    width: 160,
  },
  {
    title: '操作',
    dataIndex: 'operate',
    fixed: 'right',
    width: 230,
    search: false,
  },
];
